package com.sixmac.controller;

import com.sixmac.annotation.AuthUser;
import com.sixmac.common.base.BaseController;
import com.sixmac.core.plugins.dao.Db;
import com.sixmac.core.toolbox.ajax.AjaxResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by admin on 2018/9/4.
 */
@Controller
@RequestMapping("/region")
@ResponseBody
public class RegionController extends BaseController {
    /**
     * @api {post} /region/province 0.1获取省
     * @apiName region.province
     * @apiGroup region
     * @apiParam {String} token token
     * @apiSuccess {String} user.provinceCode provinceCode
     * @apiSuccess {String} user.province 名字
     */
    @AuthUser
    @RequestMapping("/province")
    public AjaxResult getProvince() {
        return json(getData("province", Db.selectList("select provinceCode,province from t_region_province")));
    }

    /**
     * @api {post} /region/city 0.2获取市
     * @apiName region.city
     * @apiGroup region
     * @apiParam {String} token token
     * @apiParam {String} provinceCode provinceCode
     * @apiSuccess {String} user.cityCode cityCode
     * @apiSuccess {String} user.city 名字
     */
    @AuthUser
    @RequestMapping("/city")
    public AjaxResult city(String provinceCode) {
        return json(getData("province", Db.selectList("select cityCode,city from t_region_city where provinceCode=#{provinceCode}", getData("provinceCode", provinceCode))));
    }

    /**
     * @api {post} /region/area 0.3获取区
     * @apiName region.area
     * @apiGroup region
     * @apiParam {String} token token
     * @apiParam {String} cityCode cityCode
     * @apiSuccess {String} user.areaCode areaCode
     * @apiSuccess {String} user.city 名字
     */
    @AuthUser
    @RequestMapping("/area")
    public AjaxResult area(String cityCode) {
        return json(getData("cityCode", Db.selectList("select areaCode,area from t_region_area where cityCode=#{cityCode}", getData("cityCode", cityCode))));
    }


}
